package models

import (
	log "github.com/astaxie/beego/logs"
	"github.com/astaxie/beego/orm"
	"time"
)

type IpccRecordFile struct {
	Id         int
	AppId      string
	Caller     string
	Callee     string
	CallId     string
	RecordUrl  string
	CreateTime time.Time
	Expair     time.Time
}

func SaveRecordToDb(records []*IpccRecordFile) bool {

	num := len(records)
	if 0 == num || nil == records {
		return false
	}

	o := orm.NewOrm()
	o.Using("default")

	succNum, err := o.InsertMulti(num, records)
	if err != nil || num != int(succNum) {
		log.Error("insert to db failed :%v,success:%v,want to:%v!", err, succNum, num)
		return false
	}

	return true
}

func RegIpccRecord() {
	orm.RegisterModel(new(IpccRecordFile))
}
